﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace HOG.Controls
{
    public partial class ItemsList : UserControl
    {
        public ItemsList()
        {
            InitializeComponent();
            blur.Radius = 3;
        }

        Dictionary<string, TextBlock> nameTextBlock = new Dictionary<string, TextBlock>();
        BlurEffect blur = new BlurEffect();

        /// <summary>
        /// Set up the list of items
        /// </summary>
        /// <param name="itemsList">items name</param>
        public void SetItemsList(IEnumerable<string> itemsList)
        {
            this.ItemsRoot.Children.Clear();
            nameTextBlock.Clear();
            foreach (string item in itemsList)
            {
                TextBlock t = new TextBlock();
                t.Text = item;
                t.FontSize = 12.0;
                t.Margin = new Thickness(2, 2, 10, 2);
                nameTextBlock.Add(item, t);
                this.ItemsRoot.Children.Add(t);
            }
        }

        /// <summary>
        /// Blures found item and puts it on the end
        /// </summary>
        /// <param name="itemName">item name</param>
        public void ItemFound(string itemName)
        {
            nameTextBlock[itemName].Foreground = new SolidColorBrush(Colors.Gray);
            nameTextBlock[itemName].Effect = blur;
            this.ItemsRoot.Children.Remove(nameTextBlock[itemName]);
            this.ItemsRoot.Children.Add(nameTextBlock[itemName]);
        }
    }
}
